<template>
    <div class="move-to-apply">
        <div class="mb-8px">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item
                    :to="item.path"
                    v-for="item in applyInfo.crumbData"
                    :key="item.path"
                >{{ item.title }}</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <!-- 基本信息 -->
        <user-info
            @back="goback"
            :fromPath="applyInfo.fromPath"
            :personInfo="applyInfo.personInfo"
            v-if="applyInfo.isShow"
        ></user-info>
        <!-- 申请明细 -->
        <el-card shadow="never">
            <div slot="header" class="clearfix">
                <span style="font-size:16px;font-weight:bold;line-height:32px;">申请明细</span>
                <el-button
                    style="float: right; padding: 3px 0"
                    v-if="!applyInfo.isShow"
                    @click="goback(true)"
                >返回</el-button>
            </div>
            <el-form
                label-position="right"
                label-width="160px"
                :model="applyDetailsForm"
                :rules="applyDetailsRules"
                ref="applyDetailsForm"
            >
                <el-row class="first-details">
                    <el-col :span="8">

                        <el-form-item label="异动大类:" prop="classId">
                            <DictSelect
                                v-model="applyDetailsForm.classId"
                                :data="options.abnormalCategories"
                                :clearable="false"
                                @change="handlerAbnormalCategories"
                            ></DictSelect>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="异动类型:" prop="typeCode">
                            <DictSelect
                                v-model="applyDetailsForm.typeCode"
                                :data="options.abnormalType"
                                :clearable="false"
                                @change="handlerAbnormalType"
                            ></DictSelect>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8" v-if="options.abnormalReason.length > 0">
                        <el-form-item label="异动原因:" prop="reasonId">
                            <DictSelect
                                v-model="applyDetailsForm.reasonId"
                                :data="options.abnormalReason"
                                :clearable="false"
                            ></DictSelect>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8" v-if="!needEffectiveImmediately">
                        <el-form-item label="异动开始时间:" prop="abnormalStartTime">
                            <el-date-picker
                                style="width: 100%;"
                                v-model="applyDetailsForm.abnormalStartTime"
                                type="date"
                                value-format="timestamp"
                                placeholder="选择日期"
                            ></el-date-picker>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8" v-if="!needEffectiveImmediately">
                        <el-form-item label="异动结束时间:" prop="abnormalEndTime">
                            <el-date-picker
                                v-model="applyDetailsForm.abnormalEndTime"
                                style="width: 100%;"
                                value-format="timestamp"
                                type="date"
                                placeholder="选择日期"
                            ></el-date-picker>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row class="second-details" v-if="abnormalField.length">
                    <el-col :span="8" v-for="(fieldItem, index) in abnormalField" :key="index">
                        <!-- :disabled="isOperate(fieldItem)"  原本<DictSelect/>组件中 disabled 是由isOperate（）计算得来,偶现不生效情况。
                            换成fieldItem.ifUpdate 测试偶现问题是否能修复
                        -->
                        <template>
                            <template v-if="fieldItem.visiable">
                                <el-form-item :label="'“' + fieldItem.fieldName + '”' + '调整为：'" label-width="160px">
                                    <DictSelect
                                        v-if="fieldItem.valueType === 'select' && fieldItem.fieldId != 68 && fieldItem.fieldId != 69 && fieldItem.fieldId != 62 && fieldItem.fieldId != 248"
                                        v-model="fieldItem.fieldValue"
                                        @change="selectChange(fieldItem.fieldId)"
                                        :data="fieldItem.options"
                                        :disabled="!fieldItem.ifUpdate"
                                        :clearable="false"
                                    ></DictSelect>
                                    <el-select
                                        v-if="fieldItem.fieldId == '68'"
                                        v-model="fieldItem.fieldValue"
                                        filterable
                                        :disabled="!fieldItem.ifUpdate"
                                        style="width:100%"
                                        :clearable="false"
                                        >
                                        <el-option
                                        v-for="item in options.statusProfession"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value" />
                                    </el-select>
                                    <el-select
                                        v-if="fieldItem.fieldId == '62' || fieldItem.fieldId == '248'"
                                        v-model="fieldItem.fieldValue"
                                        filterable
                                        :disabled="!fieldItem.ifUpdate"
                                        @change="selectChange(fieldItem.fieldId)"
                                        style="width:100%"
                                        :clearable="false"
                                        >
                                        <el-option
                                        v-for="item in options.facultyList"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value" />
                                    </el-select>
                                    <el-select
                                        v-if="fieldItem.fieldId == '69'"
                                        v-model="fieldItem.fieldValue"
                                        :disabled="!fieldItem.ifUpdate"
                                        @change="getZYFX(fieldItem.fieldValue,'change')"
                                        style="width:100%"
                                        :clearable="false"
                                        >
                                        <el-option
                                        v-for="item in options.PYZZ"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value" />
                                    </el-select>
                                    <el-input
                                        v-if="fieldItem.valueType === 'input' && fieldItem.fieldId != '77' && fieldItem.fieldId != '78'"
                                        v-model="fieldItem.fieldValue"
                                        :disabled="!fieldItem.ifUpdate"
                                        clearable
                                    ></el-input>
                                    <el-select
                                    v-if="fieldItem.fieldId == '77' || fieldItem.fieldId == '78'"
                                    v-model="fieldItem.fieldValue"
                                    :remote-method="getTeacher"
                                    filterable
                                    remote
                                    :disabled="!fieldItem.ifUpdate"
                                    :clearable="false"
                                    style="width:100%"
                                    @input="testClick">
                                    <el-option
                                        v-for="item in options.teachersList"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value" />
                                    </el-select>
                                    <template v-if="fieldItem.valueType == 'date' ">
                                        <DictSelect
                                            v-if="
                                               fieldItem.fieldValueType === 'select' && fieldItem.fieldId != '76' && fieldItem.fieldId != '83' && fieldItem.fieldId != '75'
                                            "
                                            v-model="fieldItem.fieldValue"
                                            :disabled="!fieldItem.ifUpdate"
                                            :data="options.changeType"
                                            :clearable="false"
                                        ></DictSelect>
                                        <DictSelect
                                            v-if="fieldItem.fieldId == '92'"
                                            :disabled="!fieldItem.ifUpdate"
                                            v-model="fieldItem.fieldValue"
                                            :data="options.changeDate"
                                            :clearable="true" />
                                            <DictSelect
                                            v-if="fieldItem.fieldId == '83' && fieldItem.fieldValueType === 'select'"
                                            :disabled="!fieldItem.ifUpdate"
                                            v-model="fieldItem.fieldValue"
                                            :data="options.studyDate"
                                            :clearable="true" />

                                        <el-date-picker
                                            v-if="(fieldItem.fieldValueType === 'int') && fieldItem.fieldId != '92' && fieldItem.fieldId != '83'"
                                            v-model="fieldItem.fieldValue"
                                            :disabled="!fieldItem.ifUpdate"
                                            type="date"
                                            style="width:100%"
                                            placeholder="选择日期"
                                        ></el-date-picker>
                                    </template>
                                    <el-date-picker
                                        v-if="(fieldItem.valueType == 'year' || fieldItem.fieldId == '83') && fieldItem.fieldValueType === 'int'"
                                        :disabled="!fieldItem.ifUpdate"
                                        v-model="fieldItem.fieldValue"
                                        type="year"
                                        style="width:100%"
                                        placeholder="选择年级"
                                         @change="selectChange(fieldItem.fieldId)"
                                        value-format="yyyy"
                                    ></el-date-picker>
                                    <DictSelect
                                            v-if="(fieldItem.fieldId == '76' || fieldItem.fieldId == '75') &&  fieldItem.fieldValueType === 'select'"
                                            :disabled="!fieldItem.ifUpdate"
                                            v-model="fieldItem.fieldValue"
                                            :data="options.comeGrade"
                                            :clearable="true" />
                                </el-form-item>
                            </template>
                        </template>
                    </el-col>
                </el-row>
                <el-row class="third-details">
                    <el-col :span="16">
                        <el-form-item label="原因说明:" prop="remark" :rules="[{ required: projectId != 1, message: '请输入原因', trigger: 'blur' }]">
                            <el-input
                                v-model="applyDetailsForm.remark"
                                type="textarea"
                                maxlength="100"
                            ></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="16" v-if="showIf && oaInputShow">
                        <el-form-item label="OA文号:" prop="oaWH">
                            <el-input maxlength="50" v-model="applyDetailsForm.oaWH" type="input"></el-input>
                        </el-form-item>
                    </el-col>

                    <el-col :span="16" v-if="applyDetailsForm.proxyReason || showProxyReason">
                        <el-form-item label="代理理由:" prop="proxyReason">
                            <el-input
                                type="textarea"
                                maxlength="500"
                                v-model="applyDetailsForm.proxyReason"
                            ></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="20">
                        <el-form-item
                            label="申请材料:"
                            ref="upload"
                            prop="attachFile"
                            :required="required"
                        >
                            <div style="display:flex;flex-direction:row;align-items:center">
                                <el-upload
                                    :headers="{
                                        'X-Token':
                                            $store.state.session.sessionid
                                    }"
                                    :data="{
                                        bucketname: 'face',
                                        folderpath: 'file'
                                    }"
                                    action="/api/commonservice/obsfile/uploadfile"
                                    :on-success="handlerSuccess"
                                    :on-error="handlerError"
                                    :before-upload="beforeUpload"
                                    :on-remove="handlerRemove"
                                    :on-exceed="handleRemove"
                                    :file-list="applyDetailsForm.attachFile"
                                    :v-model="applyDetailsForm.attachFile"
                                    limit="3"
                                >
                                    <el-button size="small" type="primary">
                                        <i class="el-icon-upload el-icon--left"></i>上传附件
                                    </el-button>
                                </el-upload>
                                <span
                                    style="margin-left:8px;color:rgb(107,121,136);font-size:12px"
                                >上传要求：请上传rar,zip,doc,docx,xls,xlsx,jpg,bmp,png,pdf格式的文件，且不超过10M</span>
                            </div>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <div class="btnGroup text-right">
                <el-button
                    type="primary"
                    v-if="this.$route.query.type == 'abnormalManage' && !global.isAdmin && !global.isAcdemicDean"
                    @click="showMsg('0')"
                >保存</el-button>
                <el-button type="primary" @click="showMsg('1')">提交</el-button>
            </div>
        </el-card>
        <el-dialog title="申请此类异动需完成以下所有课程的退课，是否确定" :visible.sync="dialogTableVisible" width="700px">
        <el-table :data="gridData" style="margin-bottom: 30px">
            <el-table-column type="index"   label="序号" width="150"></el-table-column>
            <el-table-column property="courseCode" label="课程序号" width="200"></el-table-column>
            <el-table-column property="courseName" label="课程名称"></el-table-column>
        </el-table>
        <div style="height: 25px;">
            <el-button type="primary" style="float:right;"   @click="saveOrSubmit()">确定</el-button>
            <el-button type="primary" style="float:right; margin-right:20px" @click="cancel()">取消</el-button>
        </div>
        </el-dialog>
    </div>
</template>
<script>
import { queryDic, queryZYFX } from 'common/src/api/dictionary'
import UTILS from 'common/src/utils/utils'
import { findStatusProfessionList, allFacultyList } from 'common/src/api/studentinfo'
import * as UIndex from 'common/src/utils
import { findTeacherList } from 'common/src/api/culture/change';
import * as API from 'common/src/api/abnormalType/abnormal'
import * as applyApi from 'common/src/api/studentStatus/abnormalToApply'
import userInfo from './components/userInfo'
import moment from "moment";
import mixin from 'common/src/mixins/index';
export default {
    name: 'moveToApply',
    mixins: [mixin],
    components: {
        userInfo
    },
    mixins: [mixin],
    data() {
        // 学生附件必填 非学生不必填
        // let validateFile = (rule, value, callback) => {
        //     if (value.length == 0 && this.global.isStudent == true) {
        //         callback(new Error('请上传文件'));
        //     } else {
        //         callback();
        //     }
        // };
        var checkFile = (rule, value, callback) => {
            if (!value.length) {
                callback('请上传文件')
            } else {
                callback()
            }
        };
        return {
            required: false, // 附件的必填标识
            dialogTableVisible: false,
            subType: '',
            gridData:[],
            options: {
                abnormalCategories: [],
                abnormalType: [],
                teachersList: [],
                statusProfession:[],
                abnormalReason: [],
                PYZZ: [],
                changeType: [
                    {
                        value: '0',
                        label: '异动生效时间'
                    },
                    {
                        value: '1',
                        label: '审批通过时间'
                    }
                ],
                changeDate: [],
                comeGrade: [],
                studyDate: [],
                facultyList: [] // 所有学院
            },
            applyInfo: {
                crumbData: [],
                fromPath: '',
                personInfo: null,
                isShow: false, //控制个人基本信息展示，控制申请列表的返回按钮显示
                saveType: ''
            },
            professionParm: {
                grade: '', // 当前年级
                statusFacultyList: [], // 学院
            },
            dicParm: {
                degreeType: '', // 学位类型
                grade: '', // 当前年级
                trainingLevel: '', // 培养层次
                facultys: [] // 学院

            },
            xy: '',
            nj: '',
            tempVal: '',
            projectId: '',
            showIf: true, // 是否显示OA文号
            abnormalField: [],
            majorDirectionName: '',
            ZYFX: '', // 专业方向
            majorDirectionCode: '',
            applyDetailsForm: {
                classId: '',
                typeCode: '',
                reasonId: '',
                abnormalStartTime: '',
                abnormalEndTime: '',
                remark: '',
                oaWH: '',
                proxyReason: '',
                attachFile: []
            },
            applyDetailsRules: {
                classId: [
                    {
                        required: true,
                        message: '请选择异动大类',
                        trigger: 'change'
                    }
                ],
                typeCode: [
                    {
                        required: true,
                        message: '请选择异动类型',
                        trigger: 'change'
                    }
                ],
                reasonId: [
                    {
                        required: true,
                        message: '请选择异动原因',
                        trigger: 'change'
                    }
                ],
                abnormalStartTime: [
                    {
                        type: 'date',
                        required: true,
                        message: '请选择异动开始时间',
                        trigger: 'blur'
                    }
                ],
                abnormalEndTime: [],
                // remark: [{ required: this.projectId != 1, message: '请输入原因', trigger: 'blur' }],
                proxyReason: [
                    {
                        required: false,
                        message: '请输入代理理由',
                        trigger: 'blur'
                    }
                ]
                // attachFile: [
                //     {
                //         type: "array",
                //         validator: validateFile,
                //         message: "请上传文件",
                //         trigger: ["change", "blur"]
                //     }
                // ]
            },
            applyDetailsFormCopy: {}, //备份申请明细数据，与返回时的数据作比较，用于返回时做保存提示
            immediateLlyBack: true, //是否直接返回
            needEffectiveImmediately: 1, //控制异动时间选择显示->立即生效 1，根据异动时间生效 0
            oaInputShow: 0, //控制oa文号输入框的显示与否-》0：不显示，1：显示
            showProxyReason: false, //控制代理理由的显示
            showTips: true //控制发起在校状态“离校”的学籍异动申请弱提示
        }
    },
    created() {
        this.projectId = this.global.projectId;
        // console.log(this.projectId,'this.projectId')
        this.initOptions();
        this.getVal();
        const user = this.mockUser ? this.mockUser : this.currentUser;
        if (user.currentRole === '1' && user.innerRoles[0] === '1' && (user.innerRoles.length > 1 ? user.innerRoles[1] !== '2' : user.innerRoles)) {
            this.showIf = true;
        }else {
            this.showIf = false;
        }
        
        if (
            Array.isArray(this.$route.query.studentInfo) &&
            this.$route.query.studentInfo.length == 1
        ) {
            this.getApplyInfo()
        } else {
            this.showProxyReason = false;
            this.applyDetailsFormCopy = _.cloneDeep(this.applyDetailsForm)
        }
        // if (this.global.isStudent == true) {
        //     this.required = true;
        // } else {
        //     this.required = false;
        // }
    },
    
    beforeRouteLeave(to, from, next) {
        if (from.path === '/moveToApply') {
            next();
            this.$refs.applyDetailsForm.resetFields()
        }
    },
    methods: {
        // 获取applyInfo
        async getApplyInfo() {
            let queryParams = this.$route.query.studentInfo[0];
            //回填异动申请明细的相关信息
            for (var key in this.applyDetailsForm) {
                if (key == 'attachFile') {
                    this.applyDetailsForm[key] = queryParams[key]
                        ? JSON.parse(queryParams[key])
                        : []
                } else if (key == 'typeCode' || key == 'reasonId') {
                    this.applyDetailsForm[key] = queryParams[key] ? queryParams[key] * 1 : ''
                } else if (key == 'classId') {
                    this.applyDetailsForm[key] = queryParams[key] ? queryParams[key] : '';
                    this.handlerAbnormalCategories(queryParams['classId'], data => {
                        if (data.length > 0) this.handlerAbnormalType(queryParams['typeCode'], 'noChange')
                    })
                } else if (key == 'abnormalStartTime') {
                    this.applyDetailsForm[key] = queryParams['abnormalStartTimeFormart']
                        ? new Date(queryParams['abnormalStartTimeFormart']).getTime()
                        : ''
                } else if (key == 'abnormalEndTime') {
                    this.applyDetailsForm[key] = queryParams['abnormalEndTimeFormart']
                        ? new Date(queryParams['abnormalEndTimeFormart']).getTime()
                        : ''
                } else {
                    this.applyDetailsForm[key] = queryParams[key] ? queryParams[key] : ''
                }
            }
            this.applyDetailsFormCopy = _.cloneDeep(this.applyDetailsForm); //备份申请明细数据，与返回时的数据作比较，用于返回时做保存提示
            let studentInfo = this.applyInfo.personInfo;
            if (studentInfo && studentInfo instanceof Array && studentInfo.length > 1) {
                this.applyInfo.isShow = false
            } else {
                this.applyInfo.isShow = true
            }
        },
        // 获取导师1/2下拉数据
        getTeacher(e) {
            findTeacherList({ keyWord: e }).then(res => {
                if (res.code == 200) {
                    this.options.teachersList = [];
                    let opts = [];
                    opts = res.data.map((item) => {
                        return {
                            label: item.name + '(' + item.code + ')',
                            value: item.code
                        };
                    });
                    this.options.teachersList = opts;
                } else {
                    throw res.code;
                }
            });
        },

        // 获取所有学院
        getFacultyList() {
            this.options.facultyList = []
            allFacultyList().then(res=> {
                if(res.code === 200 && res.data) {
                    res.data.forEach(faculty=> {
                        this.options.facultyList.push({
                        label: faculty.deptName,
                        value: faculty.deptCode
                        })
                    })
                }
            })
        },
        showMsg(key) {
            let _this = this;
            _this.subType = key;
            let flag = false;
            let parm = [];
            if(this.$route.query.studentInfo) {
                let studentInfo = this.$route.query.studentInfo;
                studentInfo.forEach(val=> {
                    parm.push(
                        {
                           studentId: val.studentId,
                           abnormalStartTimeFormart: this.applyDetailsForm.abnormalStartTime ? moment(this.applyDetailsForm.abnormalStartTime).format("YYYY-MM-DD HH:mm:ss") : ''
                        }
                    )
                })
            } else {
                parm = [
                    {
                        studentId: _this.applyInfo.personInfo.studentId,
                        abnormalStartTimeFormart: this.applyDetailsForm.abnormalStartTime ? moment(this.applyDetailsForm.abnormalStartTime).format("YYYY-MM-DD HH:mm:ss") : ''
                    }
                ]

            }
            
            // _this.options.abnormalType.forEach(val=> {
            //     if(_this.applyDetailsForm.typeCode == val.value && (val.label === "休学" || val.label === "退学") ) {
            //         flag = true
            //     }
            // });
            
            // 学籍状态为：4：休学，6：退休，21：保留学籍，弹出提示需要退课
            if(this.projectId != 1 && this.abnormalField && this.abnormalField.length > 0) {
                _this.abnormalField.forEach(val=> {
                    if(val.fieldId === '101' && (val.fieldValue == 4 || val.fieldValue == 6 || val.fieldValue == 21) ) {
                    flag = true
                    }
                })
            }

            _this.$refs.applyDetailsForm.validate(valid => {
                if(valid) {
                    if(flag) {
                        applyApi.coursesInAbnormalTime(parm).then(res=> {
                            if(res.code === 200 && res.data && res.data.length > 0) {
                                _this.dialogTableVisible = true;
                                _this.gridData = res.data
                            } else if(res.code === 200 && res.data && res.data.length === 0) {
                                _this.saveOrSubmit()
                            }
                        })
                    } else {
                        _this.saveOrSubmit()
                    }
                }
            })

        },
        cancel() {
            this.dialogTableVisible = false;
            this.gridData = []

        },
        getVal() {
            const data = {
                lang: this.$store.getters.language || 'cn',
                type: 'allChild',
                keys: ['X_YD_YJBYSJ','X_YD_RXSJ','X_YD_RXNJ']
            };
            // 获取学籍状态和培养层次数据字典信息，用于在页面中显示异动类型信息
                queryDic(data).then(res => {
                if (res.code === 200) {
                    UTILS.fillSelect(
                        {
                            changeDate: 'X_YD_YJBYSJ',
                            comeGrade: 'X_YD_RXNJ',
                            studyDate: 'X_YD_RXSJ'
                        },
                        res.data,
                        this.options
                    );
                    // 这时需要根据异动大类的code查询该大类下面所有异动类型
                }
            });
        },

        // 获取筛选条件字段下拉数据
        initOptions() {
            const data = {
                lang: this.$store.getters.language || 'cn',
                type: 'allChild',
                keys: ['G_XJDL']
            };
            const user = this.mockUser ? this.mockUser : this.currentUser;
            // 学生角色异动大类下拉数据
            if (user.type == 2) {
                applyApi.getTransactionCategory().then(res => {
                    this.options.abnormalCategories = res.data.map(item => {
                        return {
                            value: item.key,
                            label: item.value,
                            key: item.key
                        }
                    })
                })
            } else {
                // 非学生角色异动大类下拉数据
                queryDic(data).then(res => {
                    if (res.code === 200) {
                        let dataCopy = {
                            abnormalCategories: []
                        };
                        UTILS.fillSelect(
                            {
                                abnormalCategories: 'G_XJDL'
                            },
                            res.data,
                            dataCopy
                        );
                        let arrayFore = dataCopy.abnormalCategories.filter(e => e.label !== '其他');
                        let arrayBehind = dataCopy.abnormalCategories.filter(e => e.label == '其他');
                        this.options.abnormalCategories = [...arrayFore, ...arrayBehind]
                    }
                })
            }

            // 获取所有学院
            this.getFacultyList()

            //初始化页面导航，保存页面信息
            let crumbData = null;
            let queryParams = this.$route.query;

            if (queryParams.showProxyReason) {
                this.showProxyReason = queryParams.showProxyReason
            }
            if (
                queryParams.type === 'applicationByTeacher' &&
                Array.isArray(queryParams.studentInfo) &&
                queryParams.studentInfo.length == 1
            ) {
                crumbData = [
                    {
                        path: '/applicationByAcademic',
                        title: '教务员代申请'
                    },
                    {
                        path: '/moveToApply',
                        title: '异动申请'
                    }
                ];
                this.applyInfo = {
                    crumbData: crumbData,
                    fromPath: '/applicationByAcademic',
                    personInfo: queryParams.studentInfo[0]
                }
            } else if (
                queryParams.type === 'batchApply' ||
                (Array.isArray(queryParams.studentInfo) && queryParams.studentInfo.length > 1)
            ) {
                crumbData = [
                    {
                        path: '/batchAbnormalApply',
                        title: '批量异动申请'
                    },
                    {
                        path: '/moveToApply',
                        title: '异动申请'
                    }
                ];
                this.applyInfo = {
                    crumbData: crumbData,
                    fromPath: '/batchAbnormalApply',
                    personInfo:
                        queryParams.studentInfo.length > 1
                            ? queryParams.studentInfo
                            : queryParams.studentInfo[0]
                }
            } else if (queryParams && queryParams.type === 'abnormalManage') {
                crumbData = [
                    {
                        path: '/abnormalManage',
                        title: '学籍异动管理'
                    },
                    {
                        path: '/moveToApply',
                        title: '异动申请'
                    }
                ];
                this.applyInfo = {
                    crumbData: crumbData,
                    fromPath: '/abnormalManage',
                    personInfo: queryParams.studentInfo[0],
                    saveType: queryParams.saveType
                }
            }
        },
        // 获取变更字段下拉数据
        async getFieldOptions(val) {
            let params = {
                lang: this.$store.getters.language || 'cn',
                type: 'allChild',
                keys: [val.value],
                filter: {
                    facultys: [this.xy],
                    grade: this.nj
                }
            };
            if (val.value === 'G_ZY') {
                this.tempVal = val.fieldValue
            }
            if (val.value === 'X_FX') {
                // 专业方向
                this.ZYFX = val;
                if(this.tempVal) {
                // queryZYFX(this.tempVal).then(res => {
                //     // console.log(res)
                //     UTILS.fillSelect(
                //         {
                //             options: val.value
                //         },
                //         res.data,
                //         val
                //     )
                // })
                this.getZYFX(this.tempVal)
                }
            } else {
                let { data, code } = await queryDic(params);
                if (code !== 200) return;
                UTILS.fillSelect(
                    {
                        options: val.value
                    },
                    data,
                    val
                )
            }
            return val
        },
        // 获取专业方向名称
        getZYFX(val,type) {
            if(type === 'change') {
                this.abnormalField.forEach(val=> {
                if(val.fieldId == 70) {
                    val.fieldValue = ''
                    // 置空专业方向名称
                    }
                })
            }
            queryZYFX(val).then(res => {
                    // console.log(res)
                    UTILS.fillSelect(
                        {
                            options: this.ZYFX.value
                        },
                        res.data,
                        this.ZYFX
                    )
                })

        },
        // 异动大类改变时获取异动类型
        handlerAbnormalCategories(val, callBack) {
            this.applyDetailsForm.typeCode = '';
            if(!callBack) {
                this.applyDetailsForm.reasonId = ''
            }
            this.needEffectiveImmediately = 1;
            this.abnormalField = [];
            this.options.abnormalType = [];
            this.options.abnormalReason = [];
            API.getAbnormalTypeByClassCode(val).then(res => {
                let { code, data } = res;
                if (code === 200 && data) {
                    
                    data.forEach(val => {
                        if (val.inUser === 1) {
                            this.options.abnormalType.push(val)
                        }
                    })
                }
                callBack && callBack(data)
            })
        },
        // 异动类型改变
        handlerAbnormalType(val, type) {
            if(!type) {
                this.applyDetailsForm.reasonId = ""
            }
            if (this.options.abnormalType.length > 0) {
                this.abnormalTypeObj = this.options.abnormalType.find(a => a.value == val);
                //控制oa文号的显示框
                this.oaInputShow = this.abnormalTypeObj.oaNumb * 1;
                this.needEffectiveImmediately = this.abnormalTypeObj.changeType * 1;
                if (this.abnormalTypeObj.isShowChangeEndTime === 0) {
                    this.$set(this.applyDetailsRules.abnormalEndTime, 0, {
                        required: false,
                        message: '',
                        trigger: 'change'
                    })
                } else {
                    this.$set(this.applyDetailsRules.abnormalEndTime, 0, {
                        type: 'date',
                        required: true,
                        message: '请选择异动结束时间',
                        trigger: 'change'
                    })
                }
            }
            this.getAbnormalReason(val);
            this.getFieldAuth(val)
            // this.getProfessionList()
        },
        // 获取异动原因
        getAbnormalReason(val) {
            if (!val) {
                this.applyDetailsForm.reasonId = '';
                this.options.abnormalReason = []
            }
            API.getAbnormalReason(val).then(res => {
                let { code, data } = res;
                if (code === 200 && data) {
                    this.options.abnormalReason = [];
                    data.forEach(item => {
                        this.options.abnormalReason.push({
                            label: item.reason,
                            value: item.id
                        })
                    })
                }
            })
        },
        // 根据异动大类获取变更字段
        async getFieldAuth(val) {
            try {
                this.abnormalField = [];
                let formData = null;
                if (!Array.isArray(this.applyInfo.personInfo) && this.applyInfo.personInfo.formData) {
                    formData = JSON.parse(this.applyInfo.personInfo.formData)
                }
                let { code, data } = await applyApi.getFieldAuth(val);
                if (code === 200 && data) {
                    let global = this.$store.getters.getGlobal()
                    data.map(item => {
                        if (item.fieldId === '62') {
                            this.xy = item.fieldValue
                        }
                        if (item.fieldId === '76') {
                            this.nj = item.fieldValue
                        }
                        if (item.fieldId === '70') {
                            item.value = 'X_FX'
                        }
                        if (item.fieldId === '92') {
                            item.value = 'X_YD_YJBYSJ'
                        }
                        if (item.fieldId === '77' || item.fieldId === '78') {
                            this.getTeacher(item.fieldValue)
                        }
                        if (formData) {
                            item.fieldValue = formData[item.fieldId] ? formData[item.fieldId] : ''
                        }

                        if(global.isStudent && item.studentUpdate == 1) {
                            item.ifUpdate = true
                        } else if(global.isAcdemicDean && item.facultyUpdate == 1) {
                            item.ifUpdate = true
                        } else if(global.isAdmin && item.collegeUpdate == 1) {
                            item.ifUpdate = true
                        }
                         
                        if (item.value) {
                            item.options = [];
                            item = this.getFieldOptions(item)
                        }
                        return item
                        
                    });
                    let flag = 0; // 判断学籍专业是否拉数据
                    let bksopt = 0; // 判断本科生培养专业是否拉数据
                    let yysopt = 0; // 判断研究生培养专业是否拉数据
                    this.abnormalField = data;
                    if(data) {
                        // 学籍专业下拉框赋值
                        data.forEach(val=> {
                            if(val.fieldId == 76 && val.fieldValue) {
                                // 当前年级
                                flag = flag + 1;
                                bksopt = bksopt + 1;
                                this.professionParm.grade = val.fieldValue
                            }
                            if(val.fieldId == 248 && val.fieldValue) {
                                // 学籍学院
                                flag = flag + 1;
                                this.professionParm.statusFacultyList.push(val.fieldValue)
                            }
                            if(val.fieldId == 62 && val.fieldValue) {
                                // 学院
                                bksopt = bksopt + 1;
                                yysopt = yysopt + 1
                            }
                            if(val.fieldId == 72 && val.fieldValue) {
                                // 培养层次
                                yysopt = yysopt + 1
                            }
                            if(val.fieldId == 96 && val.fieldValue) {
                                // 学位类型
                                yysopt = yysopt + 1
                            }
                        })
                    }
                    // projectId == 2 是研究生
                    if(this.projectId == 2 ) {
                        this.getProfessionList()
                    }
                    if(this.projectId == 1 && flag === 2) {
                        this.getProfessionList()
                    }
                    if(this.projectId == 1 && bksopt === 2) {
                        this.getPyzy().then(res=> {
                        if(res.code === 200 && res.data) {
                            for(let key in res.data.G_ZY) {
                                this.options.PYZZ.push({
                                    label: res.data.G_ZY[key],
                                    value: key
                                })
                            }
                        }
                    })
                    }
                    if(this.projectId == 2 && yysopt === 3) {
                        this.getPyzy().then(res=> {
                            if(res.code === 200 && res.data) {
                                for(let key in res.data.G_ZY) {
                                    this.options.PYZZ.push({
                                        label: res.data.G_ZY[key],
                                        value: key
                                })
                            }
                        }
                    })
                }
                    this.selectChange()
                }
            } catch (err) {
                console.log(err)
            }
        },

        selectChange(val) {
            // debugger
            //申请转入学院时，写入faculty参数
            // if (this.applyDetailsForm.classId == '300006') {
                let obj = this.abnormalField.find(a => a.fieldId * 1 == 62 && a.fieldName == '学院');
                let code = obj ? obj.fieldValue : '';
                let params = this.applyInfo.personInfo;
                if (Array.isArray(params)) {
                    params.forEach(p => (p.faculty = code))
                } else {
                    params.faculty = code
                }
                this.$set(this.applyInfo, 'personInfo', params)
            // }
            for(let i = 0; i < this.abnormalField.length; i++) {
                if(this.abnormalField[i].fieldId == 96) {
                    // 学位类型
                    this.dicParm.degreeType = this.abnormalField[i].fieldValue
                }
                if(this.abnormalField[i].fieldId == 72) {
                    // 培养层次
                    this.dicParm.trainingLevel = this.abnormalField[i].fieldValue
                }
                if(this.abnormalField[i].fieldId == 62) {
                    // 学院
                    this.dicParm.facultys.push(this.abnormalField[i].fieldValue)
                }
                if(this.abnormalField[i].fieldId == 248) {
                    // 学籍学院
                    this.professionParm.statusFacultyList = [];
                    this.professionParm.statusFacultyList.push(this.abnormalField[i].fieldValue)
                }
                if(this.abnormalField[i].fieldId == 76) {
                    // 当前年级
                    this.professionParm.grade = this.abnormalField[i].fieldValue;
                    this.dicParm.grade = this.abnormalField[i].fieldValue
                }

            }
            if(this.projectId == 1 && (val == 76 || val == 248)) {
                this.abnormalField.forEach(val=> {
                if(val.fieldId == 68) {
                    val.fieldValue = ''
                    // 置空学籍专业
                }
            });
                this.getProfessionList()
            }
            if(this.projectId == 2 && (val == 72 || val == 62 || val == 96)) {
                this.abnormalField.forEach(val=> {
                if(val.fieldId == 69) {
                    val.fieldValue = ''
                    // 置空培养专业
                    }
                });
                if(this.dicParm.grade && this.dicParm.facultys && this.dicParm.degreeType) {
                    this.getPyzy().then(res=> {
                        if(res.code === 200 && res.data) {
                            console.log('res.data.G_ZY',res.data.G_ZY)
                            for(let key in res.data.G_ZY) {
                                this.options.PYZZ.push({
                                    label: res.data.G_ZY[key],
                                    value: key
                                })
                                console.log(this.options);
                            }
                        }
                    })
                }
            }
            if(this.projectId == 1 && (val == 76 || val == 62)) {
                this.abnormalField.forEach(val=> {
                if(val.fieldId == 69) {
                    val.fieldValue = ''
                    // 置空培养专业
                    }
                });
                if(this.dicParm.grade && this.dicParm.facultys) {
                    this.getPyzy().then(res=> {
                        if(res.code === 200 && res.data) {
                            for(let key in res.data.G_ZY) {
                                this.options.PYZZ.push({
                                    label: res.data.G_ZY[key],
                                    value: key
                                })
                            }
                        }
                    })
                }
            }
            if(this.projectId == 2 && (val == 72 || val == 248 || val == 96)) {
                this.abnormalField.forEach(val=> {
                    if(val.fieldId == 69) {
                        val.fieldValue = ''
                        // 置空培养专业
                    }
                    if(val.fieldId == 68) {
                        val.fieldValue = ''
                        // 置空学籍专业
                    }
                });
                // 判断是否三个依赖数据都是有值的
                let isAllHasVal = true // 默认设定isAllHasVal变量是全都有值
                let params = {}
                const paramsKey = { '248':'statusFacultyList', '72':'trainingLevel' , '96':'studentCategory'}
                this.abnormalField.map(i => {
                    if(i.fieldId == 72 || i.fieldId == 248 || i.fieldId == 96) {
                        params[paramsKey[i.fieldId]] = i.fieldValue
                        console.log(params,'params');
                        isAllHasVal && (isAllHasVal = Boolean(i.fieldValue)) // 如果之前的数据是判断有值的，那么就判断当前的这条数据是否是有值并且赋值给isAllHasVal变量
                    }
                })
                
                isAllHasVal && (
                    // 获取学籍专业
                    this.getProfessionList(params)
                )
            }
        },

        // 获取学籍专业
        getProfessionList(params = null) {
            this.options.statusProfession = [];
            let _params = params || this.professionParm
            findStatusProfessionList(_params).then(resT=> {
                if(resT.code === 200) {
                    resT.data.forEach(val=> {
                        this.options.statusProfession.push(
                            {
                                label: val.professionName + '(' + val.professionCode + ')',
                                value: val.statusProfessionCode
                            }
                        )
                    })
                }
            })
        },
        // 获取培养专业
       async getPyzy(keys) {
            const data = {
                filter: {
                  /*degreeType: ['1'],*/
                  /*grade: 2020,*/
                },
                lang: this.$store.getters.language || 'cn',
                type: 'allChild',
                keys:['G_ZY']
            };
            this.options.PYZZ = [];

          for (let i = 0; i < this.abnormalField.length; i++) {

            if (this.abnormalField[i].fieldId == 62) {
              data.filter.facultys = [this.abnormalField[i].fieldValue];
            }
            if (this.abnormalField[i].fieldId == 76 && this.projectId == 1) {
                data.filter.grade = this.abnormalField[i].fieldValue;
            }
            if (this.abnormalField[i].fieldId == 96 && this.projectId == 2) {
                data.filter.degreeType = this.abnormalField[i].fieldValue;
                // console.log(data.filter.degreeType,'data.filter.degreeType')
            }
            if (this.abnormalField[i].fieldId == 72 && this.projectId == 2) {
                data.filter.trainingLevel = this.abnormalField[i].fieldValue;
                // console.log(data.filter.trainingLevel,'data.filter.trainingLevel')
            }
          }
            return await queryDic(data);
        },


        /**
         * 保存、提交申请
         * params {type 0:保存，1：提交}
         */
        saveOrSubmit() {
            let submitType = this.subType;
            this.$refs.applyDetailsForm.validate(valid => {
                if (valid) {
                    let params = [];
                    let obj = {};
                    let formData;
                    this.abnormalField.forEach(item => {
                        if (item['required']) {
                            if (!item.fieldValue) {
                                this.$message({
                                    type: 'warning',
                                    message: `${item.fieldName}是必填项`
                                });
                                throw 'err'
                            }
                        }
                        obj[item.fieldId] = item.fieldValue
                    });

                    /*this.majorDirectionCode = item.fieldValue;*/

                    formData = JSON.stringify(obj);

                    // if (this.applyDetailsForm.oaWH && !this.testOa(this.applyDetailsForm.oaWH)) {
                    //     this.$message({
                    //         type: 'warning',
                    //         message: 'OA文号必须是数字+字母组合'
                    //     });
                    //     return
                    // }
                    if (
                        Array.isArray(this.applyInfo.personInfo) &&
                        this.applyInfo.personInfo.length > 1
                    ) {
                        params = this.applyInfo.personInfo
                    } else {
                        params = [this.applyInfo.personInfo]
                    }
                    params = params.map(info => {
                        for (let key in info) {
                            if (String(info[key]) == 'null') info[key] = ''
                        }
                        info.formData = formData;
                        return Object.assign(info, this.applyDetailsForm, {
                            attachFile: JSON.stringify(this.applyDetailsForm.attachFile),
                            typeId: this.abnormalTypeObj.typeId,
                            typeName: this.abnormalTypeObj.label,
                            isStudent: this.global.isStudent,
                            isSysAdmin: this.global.isAdmin
                        })
                    });
                    //校验异动开始时间必须小于异动结束时间
                    if (
                        this.applyDetailsForm.abnormalEndTime &&
                        !this.needEffectiveImmediately &&
                        this.applyDetailsForm.abnormalStartTime >=
                            this.applyDetailsForm.abnormalEndTime
                    ) {
                        this.$message({
                            message: '异动结束时间必须大于异动开始时间',
                            type: 'warning'
                        });
                        return
                    }
                    // roleId  1:学籍管理员  2:学院教务员  3:导师  4:老师  5:留办老师 6:学生
                    params.map(p => {
                        return Object.assign(p, {
                            roleId: this.global.isAdmin
                                ? 1
                                : this.global.isAcdemicDean
                                ? 2
                                : this.global.isAdvisor
                                ? 3
                                : this.global.isTeacher
                                ? 4
                                : this.global.isStudyAroadOfficeTeacher
                                ? 5
                                : this.global.isStudent
                                ? 6
                                : ''
                        })
                    });
                    params.forEach(e => delete e.operatInfo);
                    //    console.log(this.applyInfo)

                    //   console.log(this.abnormalField)
                    for (let i = 0; i < this.abnormalField.length; i++) {
                        if (this.abnormalField[i].fieldId === '70') {
                            this.majorDirectionCode = this.abnormalField[i].fieldValue;
                            for (let j = 0; j < this.abnormalField[i].options.length; j++) {
                                if (
                                    this.abnormalField[i].options[j].key === this.majorDirectionCode
                                )
                                    /*alert(this.abnormalField.options[j].label);*/
                                    this.majorDirectionName = this.abnormalField[i].options[j].label
                            }
                        }
                    }

                    if (submitType === '0') {
                        params.map(p => {
                            return Object.assign(p, {
                                saveType: this.applyInfo.saveType,
                                majorDirectionCode: this.majorDirectionCode,
                                majorDirectionName: this.majorDirectionName
                            })
                        });

                        var json = JSON.parse(formData);
                        if (this.applyDetailsForm.remark.indexOf('$') < 0) {
                            this.saveFrom(params)
                        } else {
                            this.$message({
                                type: 'error',
                                message: this.$t('identificationToDoList.cannotContain')
                            })
                        }
                    } else if (submitType === '1') {
                        this.json = JSON.parse(formData);
                        params.map(p => {
                            return Object.assign(p, {
                                majorDirectionCode: this.majorDirectionCode,
                                majorDirectionName: this.majorDirectionName
                            })
                        });
                        if (this.applyDetailsForm.remark.indexOf('$') < 0) {
                            this.submitFrom(params)
                        } else {
                            this.$message({
                                type: 'error',
                                message: this.$t('identificationToDoList.cannotContain')
                            })
                        }
                    }
                }
            })
        },
        testOa(str) {
            return /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{2,100}$/.test(str)
        },
        // 保存申请
        async saveFrom(params) {
            try {
                params.forEach(e => {
                    e.projId = this.global.projectId;
                    delete e.logFormData;
                    // if(e.classId == '300008') {
                    //     this.dialogTableVisible = true

                    // }
                });

                // 异动原因“因病”，需强制上传附件，只针对研究生
                if(this.options.abnormalReason && this.global.projectId == '2') {
                    for(let i = 0; i < this.options.abnormalReason.length; i++) {
                        if(params[0].reasonId === this.options.abnormalReason[i].value && this.options.abnormalReason[i].label === '因病') {
                            if(!params[0].attachFile || params[0].attachFile.length === 0 || params[0].attachFile === '[]') {
                                return this.$message.error("请上传附件")

                            }
                        }
                    }
                }

                // 学籍状态为：4：休学，6：退休，21：保留学籍，弹出提示需要退课
                // this.abnormalField.forEach(val=> {
                //     if(val.fieldId === '101' && (val.fieldValue == 4 || val.fieldValue == 6 || val.fieldValue == 21)) {
                //         this.dialogTableVisible = true
                //     }
                // })



                let { code } = await applyApi.saveApply(params);
                if (code === 200) {
                    this.$message({
                        type: 'success',
                        message: '保存数据成功!'
                    });
                    this.goback()
                }
            } catch (err) {
                console.log(err)
            }
        },
        // 提交申请
        async submitFrom(params) {
            let _this = this;
            try {
                let logFormData = [];
                 // 异动原因“因病”，需强制上传附件，只针对研究生
                    if(this.options.abnormalReason && this.global.projectId == '2') {
                    for(let i=0; i<this.options.abnormalReason.length; i++) {
                        if(params[0].reasonId === this.options.abnormalReason[i].value && this.options.abnormalReason[i].label === '因病') {
                            if(!params[0].attachFile || params[0].attachFile.length === 0 || params[0].attachFile === '[]') {
                                return this.$message.error("请上传附件")

                            }
                        }
                    }
                }
                _this.abnormalField.forEach(e => {
                    //判断是否选择的离校字段
                    if (_this.showTips && e.fieldId == '101' && e.fieldValue == '4') {
                        _this.showTip();
                        throw 'err'
                    }

                    let code = '';
                    let value = '';
                    let lsValueKey = '';
                    if(e.fieldValue && this.options.changeDate) {
                        this.options.changeDate.forEach(val=> {
                            if(val.value === e.fieldValue) {
                                lsValueKey = val.label
                            }
                        })

                    }
                    let lsComeGrade = '';
                    if(e.fieldValue && this.options.comeGrade) {
                        this.options.comeGrade.forEach(val=> {
                            if(val.value === e.fieldValue) {
                                lsComeGrade = val.label
                            }
                        })

                    }
                    let lsStudyDate = '';
                    if(e.fieldValue && this.options.studyDate) {
                        this.options.studyDate.forEach(val=> {
                            if(val.value === e.fieldValue) {
                                lsStudyDate = val.label
                            }
                        })

                    }

                    if (e.valueType == 'input') {
                        value = e.fieldValue
                    } else if (e.valueType == 'select') {
                        if (e.fieldId == '68') {
                            let xjObj = this.options.statusProfession.find(o => o.value == e.fieldValue);
                            code = e.fieldValue;
                            value = xjObj ? xjObj.label.substring(0,(xjObj.label).lastIndexOf('(')) : ''
                        }
                        if (e.fieldId == '62' || e.fieldId == '248') {
                            let obj = this.options.facultyList.find(o => o.value == e.fieldValue);
                            code = e.fieldValue;
                            value = obj ? obj.label : ''
                        }
                        if (e.options && e.fieldId != '68' && e.fieldId != '69'  && e.fieldId != '62' && e.fieldId != '248') {
                            let obj = e.options.find(o => o.value == e.fieldValue);
                            code = e.fieldValue;
                            value = obj ? obj.label : ''
                        }
                        if (_this.options && _this.options.PYZZ && e.fieldId == '69') {
                            let obj = _this.options.PYZZ.find(o => o.value == e.fieldValue);
                            code = e.fieldValue;
                            value = obj ? obj.label : ''
                        }
                    } else if (e.valueType == 'date') {
                        let keyTime = e.fieldValue;
                        if (e.fieldId == '93' || e.fieldId == '110') {
                            // value = UIndex.parseTime(e.fieldValue, '{y}-{m}-{d}')
                            if(e.fieldValue && e.fieldValue.length !== 1) {
                                value = moment(e.fieldValue).format('YYYY-MM-DD');
                            } else if(e.fieldValue.length === 1) {
                                value = keyTime == '0' ? '异动生效时间' : '审核通过时间'
                            }else {
                                value = ""
                            }
                        } else if (keyTime.constructor === String) {
                            if (keyTime.length === 1 && !lsStudyDate) {
                                value = keyTime == '0' ? '异动生效时间' : '审核通过时间'
                            } else if(lsValueKey) {
                                value = lsValueKey
                            }else if(lsStudyDate) {
                                value = lsStudyDate
                            }
                             else {
                                value = keyTime
                            }
                        }
                    } else if (e.valueType == 'year') {
                        if(lsComeGrade) {
                            value = lsComeGrade
                        } else {
                            value = e.fieldValue
                        }

                    }
                    logFormData.push({
                        key: e.fieldId,
                        keyValue: e.fieldName,
                        code: code,
                        value: value,
                        dictCode: e.value ? e.value : ''
                    })
                });
                params.forEach(e => (e.logFormData = logFormData));

                for (let U = 0; U < params[0].logFormData.length; U++) {
                    if (params[0].logFormData[U].key === '83' && this.json[83].length >= 10) {
                        params[0].logFormData[U].value = this.json[83].substring(0, 10)
                    }
                    if (params[0].logFormData[U].key === '92' && this.json[92].length >= 10) {
                        params[0].logFormData[U].value = this.json[92].substring(0, 10)
                    }
                    // if (params[0].logFormData[U].key === '93' && this.json[93].length >= 10) {
                    //     params[0].logFormData[U].value = this.json[93].substring(0, 10)
                    // }
                    // if (params[0].logFormData[U].key === '110' && this.json[110].length >= 10) {
                    //     params[0].logFormData[U].value = this.json[110].substring(0, 10)
                    // }
                }

                const res = await applyApi.addApply(params);
                if (res.code == 200) {
                    _this.$message({
                        type: 'success',
                        message: '提交申请成功!'
                    });
                    _this.goback()
                }
            } catch (err) {
                console.log(err)
            }
        },
        //申请休学、退学的异动大类时，弱提示
        showTip() {
            let _this = this;
            // _this.$alert('申请此类异动需完成所有课程的退课，是否确定', '提示', {
            //     confirmButtonText: '确定',
            //     callback: action => {
            //         if (action == 'confirm') {
            //             _this.showTips = false
            //             _this.saveOrSubmit('1')
            //         }
            //     }
            // })
            _this.showTips = false;
            _this.saveOrSubmit('1')
        },
        // 返回列表页
        goback(isNeedCheckUpdate = false) {
            this.isNeedCheckUpdate = isNeedCheckUpdate;
            if (this.isNeedCheckUpdate) {
                for (var key in this.applyDetailsForm) {
                    if (
                        _.cloneDeep(this.applyDetailsForm)[key] + '' !==
                        this.applyDetailsFormCopy[key] + ''
                    ) {
                        this.immediateLlyBack = false;
                        break
                    }
                }
            }
            if (this.immediateLlyBack) {
                this.$store.commit('delete_tabs', this.$route.path);
                if(this.$route.query.editType === 'adminEdit') {
                    this.$router.push({
                        path: "/abnormalManage",
                        query: {
                             editType: 'adminEdit',
                             routerQuery: this.$route.query.routerQuery,
                             extralQuery: this.$route.query.extralQuery,
                        }
                    });
                }
                this.$router.go(-1)
            } else {
                this.showMessageBox()
            }
        },
        //显示确认模态框
        showMessageBox() {
            this.$confirm('返回将不会保存当前设置，是否确定?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            })
                .then(() => {
                    this.immediateLlyBack = true;
                    this.isNeedCheckUpdate = false;
                    this.goback()
                })
                .catch(() => {
                    this.immediateLlyBack = true;
                    this.isNeedCheckUpdate = false
                })
        },
        //移除文件回调
        handlerRemove(file, fileList) {
            this.applyDetailsForm.attachFile = this.applyDetailsForm.attachFile.filter(
                e => e.name !== file.name
            )
        },
        handleRemove() {
            this.$message({
                message: '申请材料最多上传3个！',
                type: 'error'
            })
        },
        //上传文件成功回调
        handlerSuccess(response, file, fileList) {
            this.$refs['upload'].clearValidate();
            let responseCode = response.code;
            if (responseCode === 200) {
                let obj = {
                    name: file && file.name,
                    url: file.response.data[file.name] && file.response.data[file.name].objectkey
                };
                this.applyDetailsForm.attachFile.push(obj)
            } else {
                this.$message({
                    message: '文件列名错误或文件为空！',
                    type: 'error'
                })
            }
        },
        //上传文件失败回调
        handlerError(rresponse, file, fileList) {
            this.$message({
                message: '上传失败！',
                type: 'error'
            })
        },
        beforeUpload(file) {
            return UTILS.checkFile(
                file,
                {
                    name: '.rar,.zip,.doc,.docx,.xls,.xlsx,.jpg,.bmp,.png,.pdf',
                    size: '10'
                },
                this
            )
        }
    },
    computed: {
        currentUser() {
            if (this.$store.state.session.user) {
                return this.$store.state.session.user
            }
            return JSON.parse(localStorage.getItem('user'))
        },
        mockUser() {
            if (this.$store.state.session.mockUser) {
                return this.$store.state.session.mockUser
            }
            let sessiondata = JSON.parse(localStorage.getItem('sessiondata'));
            if (sessiondata && sessiondata.mockUser) {
                return sessiondata.mockUser
            }
        },
        //判断当前角色，处理字段权限设置
        isOperate() {
            return function(params) {
                let global = vueApp.global;
                let result = false;
                if (global.isStudent) {
                    result = params.studentUpdate * 1 == 1
                } else if (global.isAcdemicDean) {
                    result = params.facultyUpdate * 1 == 1
                } else if (global.isAdmin) {
                    result = params.collegeUpdate * 1 == 1
                }
                return !result
            }
        }
    }
}
</script>
<style lang="scss" scoped>
.move-to-apply {
    .basicInfo-title {
        overflow: hidden;
        margin-bottom: 32px;
    }
    .first-details,
    .second-details {
        border-bottom: 1px solid #ccc;
    }
    .first-details,
    .second-details,
    .third-details {
        padding-top: 16px;
    }
    .btnGroup {
        margin-top: 40px;
    }
}
</style>
